#! /usr/bin/env python
# -*- coding: utf-8 -*-

import os
import sys
import re
import datetime
import time
import locale

import clancamentos
import csaldo
import idespesa
import ireceita
import exit

locale.setlocale(locale.LC_ALL, 'pt_BR.UTF-8')

class FinancesCore:

	#Main function. Create a menu and files needed to work
	def main():
	
		cla = clancamentos.ConsultaLancamentos()
		ex = exit.Exit()
		csa = csaldo.ConsultaSaldo()
		ide = idespesa.InsereDespesa()
		ire = ireceita.InsereReceita()
		#check if hiden dir ".personal-finances" exists, if not, crete it.
		#mount main menu
		print '''	
				OPÇÃO		AÇÃO
				=====		===\n
				D		INSERIR DESPESA
				R		INSERIR RECEITA
				L		CONSULTAR LANÇAMENTOS
				S		CONSULTAR SALDO
				Q		SAIR\n
		'''

		op = raw_input('\t\tSELECIONE UMA OPÇÃO DO MENU: ')
		#parse option. can be better use another method.
		if op == 'L'or op == 'l':
			print '\n'
			cla.clanc()
		elif op == 'D' or op == 'd':
			print '\n'
			ide.idespesa()
		elif op == 'R' or op == 'r':
			print '\n'
			ire.ireceita()
		elif op == 'S' or op == 's':
			print '\n'
			csa.csaldo()
		elif op == 'Q' or op == 'q':
			print '\n'
			ex.sair()
		else:
			print '\n\t\tOPÇÃO INVÁLIDA.'
			time.sleep(1)
			os.system('clear')
			main()

	while True:
		main()
